home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / JOYSTICK.SWG / 0013_Joystick.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  3KB  |  104 lines

  1. {
  2. Here is a little something that I made up.. It kinda works w/ a Gravis GamePad
  3. (w/ 4 buttons)..
  4. }
  5. {Joystick Test - by Christopher J. Chandra - Freeware}
  6.  
  7. uses dos,crt;
  8. var x,y,lx,ly,u,r,b,l:byte;
  9.     z1,z2,z3,z4:byte;          {the buttons}
  10.  
  11. procedure joy_read(var x1,y1,b1,b2,b3,b4:byte);
  12. var result:byte;
  13.     r:registers;
  14. begin
  15. asm
  16.  mov ax,$8400
  17.  xor dx,dx
  18.  int 15h                       {get the buttons}
  19.  mov result,al
  20. end;
  21.  if result and 16 = 16 then b1:=0 else b1:=1;
  22.  if result and 32 = 32 then b2:=0 else b2:=1;
  23.  if result and 64 = 64 then b3:=0 else b3:=1;
  24.  if result and 128=128 then b4:=0 else b4:=1;
  25.  with r do
  26.  begin
  27.   ax:=$8400;
  28.   dx:=$0001;                    {get the coordinate}
  29.  end;
  30.  intr($15,r);
  31.  with r do
  32.  begin
  33.   x1:=ax;
  34.   y1:=bx
  35.  end
  36. end;
  37.  
  38. procedure calibrate(var upp,lef,bot,rig:byte);
  39. var m,m1:string;
  40. begin
  41.  m:='Center your Joystick';m1:='and press a button';
  42.  gotoxy(40-length(m) div 2,12);write(m);
  43.  gotoxy(40-length(m1) div 2,13);write(m1);
  44.  repeat
  45.   joy_read(x,y,z1,z2,z3,z4)
  46.  until (z1<>0) or (z2<>0) or (z3<>0) or (z4<>0);
  47.  lx:=x;ly:=y;
  48.  clrscr;
  49.  z1:=0;z2:=0;z3:=0;z4:=0;delay(500);
  50.  m:='Move your Joystick to the Upper Left corner';
  51.  gotoxy(40-length(m) div 2,12);write(m);
  52.  gotoxy(40-length(m1) div 2,13);write(m1);
  53.  repeat
  54.   joy_read(x,y,z1,z2,z3,z4)
  55.  until (z1<>0) or (z2<>0) or (z3<>0) or (z4<>0);
  56.  lef:=x;upp:=y;
  57.  clrscr;
  58.  z1:=0;z2:=0;z3:=0;z4:=0;delay(500);
  59.  m:='Move your Joystick to the Bottom Right corner';
  60.  gotoxy(40-length(m) div 2,12);write(m);
  61.  gotoxy(40-length(m1) div 2,13);write(m1); {<-waste of time, eh?}
  62.  repeat
  63.   joy_read(x,y,z1,z2,z3,z4)
  64.  until (z1<>0) or (z2<>0) or (z3<>0) or (z4<>0);
  65.  rig:=x;bot:=y;
  66.  clrscr;
  67.  z1:=0;z2:=0;z3:=0;z4:=0;delay(500)
  68. end;
  69.  
  70. var xx,yy,a:byte;
  71.  
  72. begin
  73.  textcolor(7);textbackground(0);clrscr;
  74.  {turn the cursor off if you want over here..}
  75.  xx:=40;yy:=12;
  76.  calibrate(u,l,b,r);
  77.  a:=178;                  {just a cursor character}
  78.  repeat
  79.   gotoxy(xx,yy);write(chr(a));
  80.   joy_read(x,y,z1,z2,z3,z4);
  81.   if z1=1 then begin textcolor(7);textbackground(1) end else
  82.   if z2=1 then begin textcolor(7);textbackground(4) end else
  83.   begin textcolor(7);textbackground(0) end;
  84.  if (z1>0) and (z3>0) then begin textcolor(7);textbackground(0);clrscr end else
  85.  if (z3>0) and (a>33) then dec(a);
  86.  if (z4>0) and (a<254) then inc(a);
  87.  gotoxy(xx,yy);write(' ');
  88.  if x<(l+5) then dec(xx,1) else  {check joystick's x against l+5}
  89.  if x>(r-5) then inc(xx,1);      {check joystick's x against r-5}
  90.  if y<(u+5) then dec(yy,1) else  {and check the y too}
  91.  if y>(b-5) then inc(yy,1);
  92.  gotoxy(1,23);write(z1:3);
  93.  gotoxy(5,23);write(z2:3);
  94.  gotoxy(9,23);write(z3:3);
  95.  gotoxy(13,23);write(z4:3);
  96.  gotoxy(1,24);write(x:3);
  97.  gotoxy(5,24);write(y:3);
  98.  gotoxy(9,24);write(lx:3);
  99.  gotoxy(13,24);write(ly:3);
  100.  if xx<1 then xx:=1 else if xx>80 then xx:=80;
  101.  if yy<1 then yy:=1 else if yy<23 then yy:=23
  102. until keypressed
  103. end.
  104.